package com.longcheng.sensordemo;

import android.content.Context;
import android.content.Intent;
import android.hardware.Sensor;
import android.hardware.SensorManager;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ListView;

import com.longcheng.sensordemo.constants.MyConstants;

import java.util.List;

/**
*添加注释测试
*/

public class MainActivity extends AppCompatActivity {
    private ListView mListView;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        mListView = (ListView) findViewById(R.id.main_listView);
        SensorManager manager = (SensorManager)
                getSystemService(SENSOR_SERVICE);
        List<Sensor> list = manager.
                getSensorList(Sensor.TYPE_ALL);
        SensorAdapter adapter = new SensorAdapter(this, list);
        if (mListView != null) {
            mListView.setAdapter(adapter);
        }

        setListener();
    }


    private void setListener() {
        mListView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                Sensor sensor = (Sensor) parent.getAdapter().getItem(position);
                int type = sensor.getType();
                Intent intent = new Intent(MainActivity.this, SecondActivity.class);
                intent.putExtra(MyConstants.type, type);
                startActivity(intent);

            }
        });
    }

}